import { Body, Controller, Get, HttpCode, Param, Post, Query } from '@nestjs/common';
import { IAdd, IAddClassify, ICreatQuestion, IEdit } from './docs.dto'
import { DocsService } from './docs.service'

@Controller('docs')
export class DocsController {
	// 注入服务
	constructor(private readonly docsService: DocsService) { }

	// 查询初始化文档列
	@Post()
	@HttpCode(200)
	list(@Body('spaceid') spaceid, @Body('type') type) {
		return this.docsService.list(spaceid, type);
	}

	// 新增文章
	@Post('add')
	@HttpCode(200)
	add(@Body() body: IAdd) {
		return this.docsService.add(body)
	}

	// 新增分类
	@Post('add_classify')
	@HttpCode(200)
	add_classify(@Body() body: IAddClassify) {
		return this.docsService.add_classify(
			body.project_id,
			body.spaceid,
			body.type,
			body.doc_parent_id,
			body.doc_title,
			body.editer
		)
	}

	@Post('search')
	@HttpCode(200)
	search(@Body('doc_id') doc_id: string, @Body('doc_title') doc_title: string, @Body('spaceid') spaceid: string, @Body('type') type: string) {
		return this.docsService.search(spaceid, type, doc_id, doc_title)
	}

	@Post('classify')
	@HttpCode(200)
	classify(@Body('spaceid') spaceid: string, @Body('type') type: string) {
		return this.docsService.classify(spaceid, type)
	}

	@Post('find')
	@HttpCode(200)
	find(@Body('doc_id') doc_id: string) {
		return this.docsService.find(doc_id)
	}

	@Post('edit')
	@HttpCode(200)
	edit(@Body() body: IEdit) {
		return this.docsService.edit(body)
	}

	@Post('del_doc')
	@HttpCode(200)
	del_doc(@Body('doc_id') doc_id: string) {
		return this.docsService.del_doc(doc_id)
	}

	@Post('del_classify')
	@HttpCode(200)
	del_classify(@Body('doc_id') doc_id: string) {
		return this.docsService.del_classify(doc_id)
	}

	@Post('add-question')
	@HttpCode(200)
	add_question(@Body() body: ICreatQuestion) {
		return this.docsService.add_question(body)
	}

	@Post('attention')
	@HttpCode(200)
	attention(@Body('doc_id') doc_id: string, @Body('user') user: string) {
		return this.docsService.attention(doc_id, user)
	}

	@Post('change_state')
	@HttpCode(200)
	change_state(@Body('question_id') question_id: string, @Body('state') state: string, @Body('user') user: string) {
		return this.docsService.change_state(question_id, state, user)
	}

}
